/*
 * REFSocketAcceptor.h
 *
 *  Created on: May 29, 2013
 *      Author: Lucifer
 */

#ifndef REFSOCKETACCEPTOR_H_
#define REFSOCKETACCEPTOR_H_

#include "REFIOEventService.h"

namespace BFX
{

class REFSocketConnection;
class REFIOEventContext;

class REFSocketAcceptor : public REFObject
{
public:
	REFSocketAcceptor(REFIOEventService* pIOService = NULL);
	virtual ~REFSocketAcceptor();

	void Listen(REFSocketAddress* pLocalAddress, int nBacklog = 0x7fffffff);
	void StopListening();
	bool IsActive() const
	{
		return m_bActive;
	}

	REFSocket* GetSocket() const;

	void BeginAccept(IOEventCallback callback);
	REFSocketConnection* EndAccept(REFIOEventContext* pContext, REFIOEventService* pIOService = NULL);

private:
	REF<REFIOEventService>	m_pIOService;
	REF<REFSocketAddress>	m_pLocalAddress;
	REF<REFSocket>	m_pSocket;
	bool	m_bActive;
};


} /* namespace BFX */
#endif /* REFSOCKETACCEPTOR_H_ */
